package com.lovegu.other;

import java.util.Comparator;
import java.util.TreeSet;
import java.util.function.BiPredicate;
import java.util.function.Consumer;
import java.util.function.Function;

/**
 * @author 老顾
 * @title: LambdaTest
 * @projectName java-restudy
 * @email: 1437594522@qq.com
 * @date 2022/9/26 16:45
 */
public class LambdaTest {
    public LambdaTest(Integer integer) {
    }

    public static void main(String[] args) {
        //无参无返回值
        Runnable r1 = () -> System.out.println("test");
        r1.run();
        //需要一个参数，但是没有返回值
        Consumer<String> con = (String str) ->{
            System.out.println(str);
        };
        con.accept("111");
        //数据类型省略，类型推断
        Consumer<String> consumer = (str) ->{
            System.out.println(str);
        };
        consumer.accept("222");
        //只要一个参数，参数小括号省略
        Consumer<String> cons = str ->{
            System.out.println(str);
        };
        cons.accept("333");
        //需要两个或者以上的参数，多条执行语句，并且可以有返回值
        Comparator<Integer> com = (x,y) ->{
            System.out.println("实现函数式接口方法！");
            return Integer.compare(x,y);
        };
        //只有一条语句时，return和大括号都可以由，则都可以省略
        Comparator<Integer> comparator = (x,y) -> Integer.compare(x,y);
    }
    Comparator<Integer> con2 = Integer::compare;
    int value = con2.compare(12,32);
    BiPredicate<String,String> bp1 = String::equals;
    Boolean s = bp1.equals("11");
}
